// pages/success/success.js
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderId:'',
    des:['正品保证',"自营品牌","极速退款","质量无忧"],
    order:[],
    info:{},
    allowShare:true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({orderId:options.orderId})
    var _this = this 
    util.request(api.orderDetails,{orderId:options.orderId}).then((res)=>{
      if(res.errno == 0){
        res.data.orderInfo.add_time = util.formatTime(new Date(res.data.orderInfo.add_time))
        if(res.data.orderInfo.order_status == 300){
          this.setData({ allowShare: true })
        }else{
          this.setData({ allowShare: false })
        }
        res.data.orderSpellPersion.iconList = res.data.orderSpellPersion.iconList.slice(0,6)
        _this.setData({ order: res.data})
      }else {
        util.showErrorToast(res.msg)
      }
    })
  },

  daoshu:function(){
    if (this.data.order){
      var obj = this.data.order.orderGoods[0]
      obj.end_time = obj.endTime
      util.daoshu(obj)
      this.setData({ info: obj })
    }

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var _this = this
    setInterval(function () {
      _this.daoshu()
    }, 1000);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (options ) {
    var _this = this
    if (options.from == 'button'){
      console.log('/pages/join/join?orderId=' + _this.data.orderId + '&id=' + _this.data.order.orderGoods[0].goods_id + "&type=join" + '&inviteUserId=' + wx.getStorageSync('userId'))
      return {
        title: '我发起了一个拼团，快来助我一臂之力',
        imageUrl: _this.data.order.orderGoods[0].list_pic_url,
        path: '/pages/join/join?orderId=' + _this.data.orderId + '&id=' + _this.data.order.orderGoods[0].goods_id + "&type=join&parent_id=" + _this.data.order.orderInfo.parent_id +'&inviteUserId='+wx.getStorageSync('userId')
      }  
    }
  }
})